#include <iterator>
#include "MarkupSTL.h"
#include "global.h"
#include "cmd.h"
#include "Game.h"
#include "RedisClient.h"
#include "Logic.h"
#include "json.h"
#include "globalExtern.h"
#include "Host.h"
#include "NodeServer.h"
//#include "900_login.pb.h"
//#include "3100_statistic_info.pb.h"
//#include "2900_event_server.pb.h"
#include "800_online.pb.h"

CGameServer::CGameServer():m_onlineCount(0)
{
}

CGameServer::~CGameServer()
{
}


bool CGameServer::InitGame()
{
	return true;
}

int CGameServer::OnBYTimeOut(int Timerid)
{
	switch (Timerid)
	{
	case TIMERID_OFFLINE_CACHE_CHECK:
	{
		procOfflineCacheCheck();
		break;
	}
	default:
		break;
	}

	return 0;
}


int CGameServer::ProcessPacket(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	int cmd = inputPkg->GetCmdType();
	switch (cmd)
	{ 
	case ONLINE_ONLINE:
	{
		onOnline(pHandler, inputPkg);
		break;
	}
	case ONLINE_OFFLINE:
	{
		onOffline(pHandler, inputPkg);
		break;
	}
	case ONLINE_STATE_QUERY:
	case ONLINE_STATE_QUERY_SYS:
	{
		onStateQuery(pHandler, inputPkg);
		break;
	}
	case online::ONLINE_CMD_ONLINE_GAME_STATE_REQ:
	{
		onOnlineGameStateQuery(pHandler, inputPkg);
		break;
	}
	case online::ONLINE_CMD_ONLINE_SYN:
	{
		onOnlineSyn(pHandler, inputPkg);
		break;
	}
	case online::ONLINE_CMD_GAME_IN_NOTIFY:
	{
		onGameIn(pHandler, inputPkg);
		break;
	}
	case online::ONLINE_CMD_GAME_OUT_NOTIFY:
	{
		onGameOut(pHandler, inputPkg);
		break;
	}
	case online::ONLINE_CMD_IN_GAME_SYN_NOTIFY:
	{
		onInGameSyn(pHandler, inputPkg);
		break;
	}
	case online::ONLINE_CMD_ONLINE_USER_LIST_REQ:{
        onOnlineUserListReq(pHandler, inputPkg);
	    break;
	}
	case online::ONLINE_CMD_ALL_USER_LIST_REQ:{
        onOnlineAllUserListReq(pHandler, inputPkg);
	    break;
	}
	default:
		{
			log_error("cmd=0x%x,  svid=%d, err no proc", cmd, pHandler->getId());
		}
		break;
	}
	return 0;
}

int CGameServer::onOnline(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	unsigned int uid = inputPkg->ReadInt();
	unsigned int agentId = inputPkg->ReadInt();
	if (!(uid > 0 && agentId > 0))
	{
		log_error("err param,uid,%d, agent,%d", uid, agentId);
		return -1;
	}
	map<unsigned int, stPlayer>::iterator itor = m_player.find(uid);
	if (m_player.end() != itor)
	{
		if (itor->second.m_agentId > 0)
		{
			if (agentId != itor->second.m_agentId)
			{
				kick(uid, itor->second.m_agentId);

				if (itor->second.m_gameSrvType > 0 && itor->second.m_gameSrvId > 0)
				{
					offlineNotify(uid, itor->second.m_agentId, itor->second.m_gameSrvType, itor->second.m_gameSrvId);
				}
			}
		}
		else
		{
			++m_onlineCount;
		}
		itor->second.m_agentId = agentId;
		rmOfflineCache(uid);

		if (itor->second.m_gameSrvType > 0 && itor->second.m_gameSrvId > 0)
		{
			onlineNotify(uid, itor->second.m_agentId, itor->second.m_gameSrvType, itor->second.m_gameSrvId);
		}
	}
	else
	{
		stPlayer player;
		player.m_agentId = agentId;
		m_player.insert(make_pair(uid, player));

		++m_onlineCount;
	}

	log_info("online,svid,%u,sum,%u", TGlobal::_svid, m_onlineCount);
	log_debug("user on,uid,%d, agent,%d", uid, agentId);
	NETOutputPacket pack;
	pack.Begin(ONLINE_ONLINE);
	pack.WriteInt(0);
	pack.End();
	pHandler->Send(&pack);

	//synOnlineNum(uid);
//     server_proto::UserOnlineNumberReq numReq;
//     numReq.set_number((uint32)m_player.size());
//     m_pHost->SendtoSrv(server_proto::EVENT_SERVER_MSG_ID_USER_ONLINE_NUMBER, SERVER_TYPE_EVENT, &numReq, uid);


	return 0;
}

int CGameServer::onOffline(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	unsigned int uid = inputPkg->ReadInt();
	if (!(uid > 0))
	{
		log_error("err param,uid,%d", uid);
		return -1;
	}

	map<unsigned int, stPlayer>::iterator itor = m_player.find(uid);
	if (m_player.end() != itor)
	{
		if (itor->second.m_agentId != pHandler->getId())
		{
			log_error("user offline error, uid:%d agentId:%d recvAgentId:%d", uid, itor->second.m_agentId, pHandler->getId());
		}
		else
		{
			if (m_onlineCount > 0)
				--m_onlineCount;
		}

		if (itor->second.m_gameSrvType > 0 && itor->second.m_gameSrvId > 0)
		{
			unsigned int agentid = itor->second.m_agentId;
			itor->second.m_agentId = 0;
			offlineCache(uid);

			offlineNotify(uid, agentid, itor->second.m_gameSrvType, itor->second.m_gameSrvId);
			log_debug("in game user off,uid,%u, agent,%u,srvtype,%u,svid,%u", uid, agentid, itor->second.m_gameSrvType, itor->second.m_gameSrvId);
		}
		else
		{
			log_debug("user off,uid,%d, agent,%d", uid, itor->second.m_agentId);
			rmOfflineCache(uid);
			m_player.erase(itor);
		}
	}

	log_debug("user off,uid,%d", uid);
	NETOutputPacket pack;
	pack.Begin(ONLINE_OFFLINE);
	pack.WriteInt(0);
	pack.End();
	pHandler->Send(&pack);

// 	client_proto::StatisticNotifyOffLineReq request;
// 	request.set_uid(uid);
// 	m_pHost->SendtoSrv(client_proto::STATISTIC_MSG_ID_NOTIFY_OFF_LINE, SERVER_TYPE_STATISTIC, &request, uid);

	//synOnlineNum(uid);
//     server_proto::UserOnlineNumberReq numReq;
//     numReq.set_number((uint32)m_player.size());
//     m_pHost->SendtoSrv(server_proto::EVENT_SERVER_MSG_ID_USER_ONLINE_NUMBER, SERVER_TYPE_EVENT, &numReq, uid);

	return 0;
}

int CGameServer::onGameIn(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	online::GameInNotify msg;
	if (!inputPkg->parsePb(&msg))
	{
		log_error("game in pb parse err");
		return 0;
	}
	if (!(msg.uid() > 0))
	{
		log_error("game in wrong uid,%u", msg.uid());
		return 0;
	}
	if (!(msg.srvtype() > 0 && msg.srvid() > 0))
	{
		log_error("game in wrong param, srvtype,%u,srvid,%u", msg.srvtype(), msg.srvid());
		return 0;
	}
	map<unsigned int, stPlayer>::iterator itor = m_player.find(msg.uid());
	if (m_player.end() != itor)
	{
		if (itor->second.m_gameSrvType > 0 && itor->second.m_gameSrvId > 0 && (itor->second.m_gameSrvType != msg.srvtype() || itor->second.m_gameSrvId != msg.srvid()))
		{
			online::ReInGameNotify notify;
			notify.set_uid(msg.uid());
			notify.set_agentid(itor->second.m_agentId);
			notify.set_new_srvtype(msg.srvtype());
			notify.set_new_srvid(msg.srvid());
			notify.set_new_tableid(msg.tableid());
			notify.set_new_access(msg.access());
			notify.set_new_accessid(msg.accessid());
			notify.set_new_game(msg.game());
			notify.set_new_gameid(msg.gameid());
			notify.set_new_level(msg.level());
			notify.set_aiflag(itor->second.m_aiFlag);

			m_pHost->SendtoOneSrv(online::ONLINE_CMD_GAME_RE_IN_NOTIFY, &notify, itor->second.m_gameSrvType, itor->second.m_gameSrvId);
			log_info("re in game,uid,%u,old srv type:%hu, old srv id,%u,old tableid,%u", msg.uid(), itor->second.m_gameSrvType, itor->second.m_gameSrvId, itor->second.m_tableId);
		}

		itor->second.m_gameSrvType = msg.srvtype();
		itor->second.m_gameSrvId = msg.srvid();
		itor->second.m_tableId = msg.tableid();
		itor->second.m_access = msg.access();
		itor->second.m_accessId = msg.accessid();
		itor->second.m_game = msg.game();
		itor->second.m_gameId = msg.gameid();
		itor->second.m_level = msg.level();
		itor->second.m_aiFlag = msg.aiflag();

		log_debug("user game in,uid,%u,srvtype,%u,srvid,%u,tid,%u", msg.uid(), msg.srvtype(), msg.srvid(), msg.tableid());
	}
	else
	{
		m_player.insert(make_pair(msg.uid(), stPlayer(0, msg.srvtype(), msg.srvid(), msg.tableid(), msg.access(), msg.accessid(), msg.game(), msg.gameid(), msg.level(), msg.aiflag())));

		log_info("user game in,no line on data,uid,%u,srvtype,%u,srvid,%u,tid,%u", msg.uid(), msg.srvtype(), msg.srvid(), msg.tableid());
	}


	return 0;
}

int CGameServer::onGameOut(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	online::GameOutNotify msg;
	if (!inputPkg->parsePb(&msg))
	{
		log_error("game out pb parse err");
		return 0;
	}
	if (!(msg.uid() > 0))
	{
		log_error("game out wrong uid,%u", msg.uid());
		return 0;
	}

	map<unsigned int, stPlayer>::iterator itor = m_player.find(msg.uid());
	if (m_player.end() != itor)
	{
		do 
		{
			if (msg.srvtype() > 0 && msg.srvid() > 0)
			{
				if (itor->second.m_gameSrvType > 0 && itor->second.m_gameSrvId > 0 && (itor->second.m_gameSrvType != msg.srvtype() || itor->second.m_gameSrvId != msg.srvid()))
				{
					log_info("game out param not match,uid,%u,old srvtyp,%hu,old srvid,%u,old tableid,%u,new srvtyp,%hu,new srvid,%u,new tableid,%u"
						, msg.uid(), itor->second.m_gameSrvType, itor->second.m_gameSrvId, itor->second.m_tableId, (unsigned short)msg.srvtype(), msg.srvid(), msg.tableid());
					break;
				}
			}
			itor->second.m_gameSrvType = 0;
			itor->second.m_gameSrvId = 0;
			itor->second.m_tableId = 0;
			itor->second.m_access = "";
			itor->second.m_accessId = 0;
			itor->second.m_game = "";
			itor->second.m_gameId = 0;
			itor->second.m_level = 0;
			itor->second.m_aiFlag = 0;
		} while (false);
	}

	log_debug("user game out,uid,%u", msg.uid());

	return 0;
}

int CGameServer::onInGameSyn(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	online::InGameSyn msg;
	if (!inputPkg->parsePb(&msg))
	{
		log_error("in game syn pb parse err");
		return 0;
	}
    
	int count = msg.list_size();
	for (int i = 0; i < count; ++i)
	{
		unsigned int uid = msg.list(i).uid();
		map<unsigned int, stPlayer>::iterator itor = m_player.find(uid);
		if (m_player.end() != itor)
		{
			itor->second.m_gameSrvType = msg.list(i).srvtype();
			itor->second.m_gameSrvId = msg.list(i).srvid();
			itor->second.m_tableId = msg.list(i).tableid();
			itor->second.m_access = msg.list(i).access();
			itor->second.m_accessId = msg.list(i).accessid();
			itor->second.m_game = msg.list(i).game();
			itor->second.m_gameId = msg.list(i).gameid();
			itor->second.m_level = msg.list(i).level();
			itor->second.m_aiFlag = msg.list(i).aiflag();

			log_debug("in game syn,uid,%u,srvtype,%u,srvid,%u,tid,%u", msg.list(i).uid(), msg.list(i).srvtype(), msg.list(i).srvid(), msg.list(i).tableid());
		}
		else
		{
			m_player.insert(make_pair(uid, stPlayer(0, msg.list(i).srvtype(), msg.list(i).srvid(), msg.list(i).tableid(), msg.list(i).access(), msg.list(i).accessid(), msg.list(i).game(), msg.list(i).gameid(), msg.list(i).level(), msg.list(i).aiflag())));
			log_debug("in game syn,no online data,uid,%u,srvtype,%u,srvid,%u,tid,%u", msg.list(i).uid(), msg.list(i).srvtype(), msg.list(i).srvid(), msg.list(i).tableid());
		}
	}

	log_debug("in game syn,count,%d", count);
	return 0;
}

int CGameServer::onStateQuery(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	//client_proto::LoginResp msg;
	//inputPkg->parsePb(&msg);

	unsigned int cmd = inputPkg->GetCmdType();
	unsigned int uid = inputPkg->ReadInt();
	if (!(uid > 0))
	{
		log_error("err param,uid,%d", uid);
		return -1;
	}

	unsigned int agentId = 0;
	map<unsigned int, stPlayer>::iterator itor = m_player.find(uid);
	if (m_player.end() != itor)
	{
		if (itor->second.m_agentId > 0)
		{
			agentId = itor->second.m_agentId;
		}
	}

	char inner[10240] = {0};
	int len = inputPkg->ReadBinary(inner, sizeof(inner));
	
	if (ONLINE_STATE_QUERY_SYS == cmd)
		cmd = ONLINE_STATE_QUERY_RSP_SYS;

	NETOutputPacket pack;
	pack.Begin(cmd);
	pack.WriteInt(uid);
	pack.WriteInt(agentId);
	if (len > 0)
	{
		pack.WriteBinary(inner, len);
	}
	pack.End();
	pHandler->Send(&pack);

	log_debug("query,uid,%d, agent,%d, len,%d, arry[0],%d,t,%d,sid,%d", uid, agentId, len, inner[0], pHandler->getType(), pHandler->getId());
	return 0;
}

int CGameServer::onOnlineGameStateQuery(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	online::OnlineGameStateResp rsp;
	online::OnlineGameStateReq msg;
	do 
	{
		if (!inputPkg->parsePb(&msg))
		{
			rsp.set_result(1);
			break;
		}
		if (!(msg.uid() > 0))
		{
			rsp.set_result(2);
			break;
		}

		rsp.set_uid(msg.uid());
		rsp.set_result(0);
		map<unsigned int, stPlayer>::const_iterator itor = m_player.find(msg.uid());
		if (m_player.end() != itor)
		{
			rsp.set_agentid(itor->second.m_agentId);
			rsp.set_gamesrvtype(itor->second.m_gameSrvType);
			rsp.set_gamesrvid(itor->second.m_gameSrvId);
			rsp.set_tableid(itor->second.m_tableId);
			rsp.set_access(itor->second.m_access);
			rsp.set_accessid(itor->second.m_accessId);
			rsp.set_game(itor->second.m_game);
			rsp.set_gameid(itor->second.m_gameId);
			rsp.set_level(itor->second.m_level);
			rsp.set_aiflag(itor->second.m_aiFlag);
		}
	} while (false);

	if (!msg.trans().empty())
	{
		rsp.set_trans(msg.trans());
	}

	m_pHost->SendPb(pHandler, online::ONLINE_CMD_ONLINE_GAME_STATE_RESP, pHandler->getType(), pHandler->getId(), &rsp);
	return 0;
}


int CGameServer::onOnlineUserListReq(SocketHandler* pHandler, NETInputPacket* inputPkg){
    online::OnlineUserListReq stReq;
    inputPkg->parsePb(&stReq);
    int operate_type = stReq.operate_type();
	for (map<unsigned int, stPlayer>::iterator itor = m_player.begin(); m_player.end() != itor; ++itor)
	{
	    uint32 uid = itor->first;
        online::OnlineUserListResp stResp;
	    stResp.set_uid(uid);
        stResp.set_operate_type(operate_type);
	    m_pHost->SendtoSrv(online::ONLINE_CMD_ONLINE_USER_LIST_RESP, pHandler->getType(), &stResp, uid);
	}
    return 0;
}
int CGameServer::onOnlineAllUserListReq(SocketHandler* pHandler, NETInputPacket* inputPkg){
    online::OnlineAllUserListReq stReq;
    inputPkg->parsePb(&stReq);
    int operate_type = stReq.operate_type();
    std::vector<std::vector<std::pair<uint32, int>>> groupData;
    std::vector<std::pair<uint32, int>> data;
    for (map<unsigned int, stPlayer>::iterator itor = m_player.begin(); m_player.end() != itor; ++itor)
    {
        uint32 uid = itor->first;
        int agentid = itor->second.m_agentId;
        data.push_back(std::pair<uint32, int>(uid, agentid));
        if(data.size() >= 1000){
            groupData.push_back(data);
            std::vector<std::pair<uint32, int>> temp;
            data.swap(temp);
        }
    }
    if(data.size() > 0){
        groupData.push_back(data);
    }
    for(int i=0; i<(int)groupData.size(); ++i){
        online::OnlineAllUserListResp stResp;
        std::vector<std::pair<uint32, int>>& d = groupData[i];
        stResp.set_operate_type(operate_type);
        for(int j=0; j<(int)d.size(); ++j){
            std::pair<uint32, int>& p = d[j];
            online::OnlineUserAgent* pData = stResp.add_uid_array();
            pData->set_uid(p.first);
            pData->set_agentid(p.second);
        }
        m_pHost->SendPb(pHandler, online::ONLINE_CMD_ALL_USER_LIST_RESP, pHandler->getType(), pHandler->getId(), &stResp);
    }
    return 0;
}

int CGameServer::onOnlineSyn(SocketHandler* pHandler, NETInputPacket* inputPkg)
{
	online::OnlineSynReq msg;
	inputPkg->parsePb(&msg);
	unsigned int agentid = msg.agentid();
	if (!(agentid > 0))
	{
		log_error("wrong agent id,%u", agentid);
		return 0;
	}
	int count = msg.uids_size();
	for (int i =0; i < count; ++i)
	{
		unsigned int uid = msg.uids(i);
		if (!(uid > 0))
			continue;

		map<unsigned int, stPlayer>::iterator itor = m_player.find(uid);
		if (m_player.end() != itor)
		{
			//log_warning("unexcepted player,uid,%d,agent,%d, new agent id,%d", uid, itor->second.m_agentId, agentid);
			//m_player.erase(itor);
			itor->second.m_agentId = agentid;
			rmOfflineCache(uid);
			if (itor->second.m_gameSrvType > 0 && itor->second.m_gameSrvId > 0)
			{
				onlineNotify(uid, agentid, itor->second.m_gameSrvType, itor->second.m_gameSrvId);
			}
			log_debug("online syn,data in map, uid,%u,agent,%u,gamesrvid,%u", uid, agentid, itor->second.m_gameSrvId);
		}
		else
		{
			stPlayer player;
			player.m_agentId = agentid;
			m_player.insert(make_pair(uid, player));
			log_debug("online syn,no data in map, uid,%u,agent,%u", uid, agentid);
		}

		++m_onlineCount;
	}

	log_info("online,svid,%u,sum,%u", TGlobal::_svid, m_player.size());
	online::OnlineSynResp rsp;
	m_pHost->SendPb(pHandler, online::ONLINE_CMD_ONLINE_SYN, pHandler->getType(), pHandler->getId(), &rsp);

	//synOnlineNum();
	return 0;
}

int CGameServer::ProcEventClientClose(int ev_id, SpiderEvent* pEvent)
{
	if (!pEvent)
		return -1;

	CClientHandler* handler = (CClientHandler*)pEvent->evParam.ptr;
	if (SERVER_TYPE_AGENT == handler->getType())
	{
		procAgentClose(handler->getId());
	}
	else if (SERVER_TYPE_ROOMSERVER == handler->getType())
	{
		procGameClose(handler->getType(), handler->getId());
	}
	return 0;
}

int CGameServer::ProcEventGameInit(int ev_id, SpiderEvent* pEvent)
{
	StartTimer(TIMERID_OFFLINE_CACHE_CHECK, g_offline_cache_timer_interval, true);
	return 0;
}

void CGameServer::procAgentClose(const unsigned int agentid)
{
	if (!(agentid > 0))
	{
		log_error("wrong agent id,%u", agentid);
		return;
	}

	for (map<unsigned int, stPlayer>::iterator itor = m_player.begin(); m_player.end() != itor; )
	{
		if (agentid == itor->second.m_agentId)
		{
			if (itor->second.m_gameSrvType > 0 && itor->second.m_gameSrvId > 0)
			{
				itor->second.m_agentId = 0;
				offlineCache(itor->first);

				offlineNotify(itor->first, agentid, itor->second.m_gameSrvType, itor->second.m_gameSrvId);
				++itor;
			}
			else
			{
				m_player.erase(itor++);
			}

			if (m_onlineCount > 0)
				--m_onlineCount;
		}
		else
			++itor;
	}

	log_debug("agent close,agentid,%u", agentid);
	//synOnlineNum();
	return;
}

void CGameServer::procGameClose(const unsigned short srvtype, const unsigned int srvid)
{
	for (map<unsigned int, stPlayer>::iterator itor = m_player.begin(); m_player.end() != itor; ++itor)
	{
		if (srvtype == itor->second.m_gameSrvType && srvid == itor->second.m_gameSrvId)
		{
			itor->second.m_gameSrvType = 0;
			itor->second.m_gameSrvId = 0;
			itor->second.m_tableId = 0;
			itor->second.m_access = "";
			itor->second.m_accessId = 0;
			itor->second.m_game = "";
			itor->second.m_gameId = 0;
			itor->second.m_level = 0;
			itor->second.m_aiFlag = 0;

			log_debug("game srv close,uid,%u,srvtype,%hu,srvid,%u", itor->first, srvtype, srvid);
		}
	}

	return;
}

void CGameServer::kick(unsigned int uid, unsigned int agentId)
{

	if (m_pHost && m_pHost->m_pNode)
	{
		NETOutputPacket pack;
		pack.Begin(ONLINE_KICK);
		pack.WriteInt(uid);
		pack.WriteInt(1);
		pack.End();
		m_pHost->m_pNode->SendPacketFromClient(&pack, SERVER_TYPE_AGENT, agentId);
	}
		
	return;
}

// void CGameServer::synOnlineNum(const unsigned int uid)
// {
// 	unsigned int dst = uid;
// 	if (0 == dst)
// 		dst = TGlobal::_svid;
// 
// 	server_proto::UserOnlineNumberReq numReq;
// 	numReq.set_stype(SERVER_TYPE_ONLINE);
// 	numReq.set_svid(TGlobal::_svid);
// 	numReq.set_number(m_onlineCount);
// 	//numReq.set_number((uint32)m_player.size());
// 	
// 	m_pHost->SendtoSrv(server_proto::EVENT_SERVER_MSG_ID_USER_ONLINE_NUMBER, SERVER_TYPE_EVENT, &numReq, dst);
// 	return;
// }

void CGameServer::offlineCache(const unsigned int uid)
{
	map<unsigned int, _u64_>::const_iterator itor = m_offlineCache.find(uid);
	if (m_offlineCache.end() == itor)
	{
		m_offlineCache.insert(make_pair(uid, ::time(NULL)));
	}
	return;
}

void CGameServer::rmOfflineCache(const unsigned int uid)
{
	m_offlineCache.erase(uid);
	return;
}

int CGameServer::procOfflineCacheCheck(void)
{
	_u64_ tt = ::time(NULL);
	for (map<unsigned int, _u64_>::iterator itor = m_offlineCache.begin(); m_offlineCache.end() != itor; )
	{
		if (tt >= itor->second + g_offline_cache_dur)
		{
			log_debug("in game user,%u time out", itor->first);
			m_player.erase(itor->first);
			m_offlineCache.erase(itor++);
		}
		else
		{
			++itor;
		}
	}

	return 0;
}
void CGameServer::onlineNotify(const unsigned int uid, const unsigned int agentid, const unsigned short srvtype, const unsigned int srvid)
{
	if (!(srvtype > 0 && srvid > 0))
	{
		return;
	}

	online::OnlineNotify notify;
	notify.set_uid(uid);
	notify.set_agentid(agentid);
	m_pHost->SendtoOneSrv(online::ONLINE_CMD_ONLINE_NOTIFY, &notify, srvtype, srvid);
	log_debug("online notify,uid,%u,agentid,%u,srvtype,%hu,srvid,%u",uid, agentid, srvtype, srvid);
	return;
}

void CGameServer::offlineNotify(const unsigned int uid, const unsigned int agentid, const unsigned short srvtype, const unsigned int srvid)
{
	if (!(srvtype > 0 && srvid > 0))
	{
		return;
	}

	online::OfflineNotify notify;
	notify.set_uid(uid);
	notify.set_agentid(agentid);
	m_pHost->SendtoOneSrv(online::ONLINE_CMD_OFFLINE_NOTIFY, &notify, srvtype, srvid);
	log_debug("offline notify,uid,%u,agentid,%u,srvtype,%hu,srvid,%u", uid, agentid, srvtype, srvid);
	return;
}
